package com.gt.controller.user;

import com.gt.pojo.PageResult;
import com.gt.pojo.Result;
import com.gt.pojo.dto.BorrowConfirmDTO;
import com.gt.pojo.dto.BorrowPageQueryDTO;
import com.gt.service.BorrowService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController(value = "userBorrowController")
@Api(tags = "图书借阅管理接口")
@RequestMapping("/user/borrow")
public class BorrowController {

    @Autowired

    private BorrowService borrowService;

    @GetMapping("/page")
    @ApiOperation("学生借阅管理接口")
    public Result<PageResult> pageQuery(BorrowPageQueryDTO borrowPageQueryDTO){
        PageResult pageResult = borrowService.Search(borrowPageQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/confirm")
    @ApiOperation("归还书籍")
    public Result returnAndRenew(@RequestBody BorrowConfirmDTO borrowConfirmDTO){
        borrowService.back(borrowConfirmDTO);
        return Result.success();
    }

    @PutMapping("/renew")
    @ApiOperation("续借书籍")
    public Result renew(@RequestBody BorrowConfirmDTO borrowConfirmDTO){
        borrowService.renew(borrowConfirmDTO);
        return Result.success();
    }
}
